﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AnimalCare.Model;

namespace AnimalCare.Service
{
    class EmployeeService
    {
        public static void Insert(string employeeName, string employeePhone, string employeeInfo)
        {
            Employee cf = new Employee();
            cf.employee_name = employeeName;
            cf.employee_phone = employeePhone;
            cf.employee_info = employeeInfo;
            using (var ctx = new AnimalCareDBEntities())
            {
                ctx.Employees.AddObject(cf);
                ctx.SaveChanges();
            }
        }

        public static void Update(Employee cf)
        {
            using (var ctx = new AnimalCareDBEntities())
            {
                var supplier = (from s in ctx.Employees
                                where s.employee_id == cf.employee_id
                                select s).FirstOrDefault();
                supplier.employee_name = cf.employee_name;
                supplier.employee_phone = cf.employee_phone;
                supplier.employee_info = cf.employee_info;
                int num = ctx.SaveChanges();
            }
        }

        public static void Delete(int id)
        {
            try
            {
                using (var ctx = new AnimalCareDBEntities())
                {
                    var cf = (from s in ctx.Employees
                              where s.employee_id == id
                              select s).FirstOrDefault();
                    ctx.Employees.DeleteObject(cf);
                    int num = ctx.SaveChanges();
                }
            }
            catch
            {
            }
        }
    }
}
